package jdbc;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;

public class JDBCDemo12 {
    public static void main(String[] args) throws SQLException {
        try(Connection conn = DBUtil.getConnection()) {
            conn.setTransactionIsolation(Connection.TRANSACTION_READ_COMMITTED);
            conn.setAutoCommit(false);
            String  sql = "INSERT INTO(username,password,nickname,age) " +
                    "VALUSE(?,?,?,?)";
            PreparedStatement ps = conn.prepareStatement(sql);
            ps.setString(1,"王刚");
            ps.setString(2,"123456");
            ps.setString(3,"老王");
            ps.setInt(4,33);
            int num = ps.executeUpdate();
            System.out.println(num>0?"添加成功":"添加失败");
            conn.commit();
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
}
